package cn.jiyun.user.service.impl;

import cn.jiyun.user.common.R;
import cn.jiyun.user.dao.GoodsDao;
import cn.jiyun.user.figen.GoodsWareOpfen;
import cn.jiyun.user.pojo.Goods;
import cn.jiyun.user.pojo.Ware;
import cn.jiyun.user.service.GoodsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Autowired
    private GoodsWareOpfen goodsWareOpfen;
    @Override
    public R findPage(Integer page, Integer pageSize) {
        Page<Goods> page1 = new Page<>();
        Page<Goods> goodsPage = goodsDao.selectPage(page1, null);
        return R.success(goodsPage);
    }

    @Override
    public void add(Goods goods) {
        goodsDao.insert(goods);
    }

    @Override
    public R findById(Integer id) {
        Goods goods = goodsDao.selectById(id);
        Ware all = goodsWareOpfen.findAll();
        Integer num = all.getNum();
        goods.setNum(num);
        return R.success(goods);
    }
}
